package com.netease.ntertainment.interview;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * @author ZhangyiA
 * @describe:
 * @date 2021/07/06
 */

public class One_SevenStars {

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        input.nextLine();
//        int[][] tiles = new int[3][3]; // 万 饼 条
        for(int i = 0 ; i < n ; i ++){
            List<Integer> wan = new ArrayList<>();
            List<Integer> bing = new ArrayList<>();
            List<Integer> tiao = new ArrayList<>();
            String str = input.nextLine();
            String[] buff = str.split(" ");
            for(String temp : buff){
                int val = temp.charAt(0) - '0';
                char type = temp.charAt(1);
                if(type == 'W') wan.add(val);
                else if(type == 'B') bing.add(val);
                else tiao.add(val);
            }
            boolean flag = true;
            // 特判缺门的情况
            if(wan.isEmpty() || bing.isEmpty() || tiao.isEmpty()){
                System.out.println("NO");
                flag = false;
            }
            if(!flag) continue; // 继续下一组的输入
            // 排序
            wan.sort(Comparator.comparingInt(Integer::intValue)); // 默认正序
            bing.sort(Comparator.comparingInt(Integer::intValue));
            tiao.sort(Comparator.comparingInt(Integer::intValue));
            // 判断万饼条内部是否满足 3 或者隔 6 的条件
            for(int j = 1 ; j < wan.size() ; j ++){
                int cha = wan.get(j) - wan.get(j - 1);
                if(cha != 3 && cha != 6){
                    flag = false;
                    break;
                }
            }
            for(int j = 1 ; j < bing.size() ; j ++){
                int cha = bing.get(j) - bing.get(j - 1);
                if(cha != 3 && cha != 6) {
                    flag = false;
                    break;
                }
            }
            for(int j = 1 ; j < tiao.size() ; j ++){
                int cha = tiao.get(j) - tiao.get(j - 1);
                if(cha != 3 && cha != 6) {
                    flag = false;
                    break;
                }
            }
            // 判断 万饼条 间元素 对 2 取模是否相互独立
            int[] count = new int[3];
            count[wan.get(0) % 3] ++;
            count[bing.get(0) % 3] ++;
            count[tiao.get(0) % 3] ++;
            if(count[0] != 0 && count[1] != 0 && count[2] != 0) flag = true;
            System.out.println(flag ? "YES" : "NO");
        }

    }

}

/*
4
1T 4T 7T 2B 5B 8B 9W
1T 2T 3T 4T 5T 6T 7T
1B 2W 3T 4B 5W 6T 8W
2B 8B 5B 1T 7T 3W 6W
* */